﻿<!DOCTYPE html>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
<link href="/SiteUI/Base.css" rel="stylesheet" />
<link href="/SiteUI/Register/Register.css" rel="stylesheet" />
<html>
<body>
    <div class="view" id="headBar">
        <div class="row">
            <div class="col-lg-5 col-lg-offset-1" id="siteLogo">

            </div>
            <div class="col-lg-6" id="siteLink">
                <a href="/Index.html">首页</a>
                <a href="/Products.html">采购云协同</a>
                <a href="/BizCase.html">案例</a>
                <a href="/AboutUS.html">关于我们</a>
            </div>
        </div>
    </div>

    <div class="view_fix" id="viewRegister">
        <div class="row step3" id="vr-steps3"></div>
        <div class="row" id="vr-success">
            <div>
                <img src="SiteUI/Imgs/acntOk.png" />
                <div>
                    <h3>您的账号已创建成功</h3>
                    <span>为了让我们更好的服务于您，请设置您所工作的企业</span>
                </div>

            </div>
        </div>
        <div class="row" id="vr-company"> 
            <div class="col-lg-6 col-lg-offset-2">
                <h5>您的企业名称：</h5>
                <input maxlength="200" id="txbCompany" placeholder="请输入您的企业名称"/>
            </div>
            <div class="col-lg-2" style="padding:0 1rem;">
                <h5>&nbsp;</h5>
                <div class="button btn-big" id="btnFind">确认</div>
            </div>
            <div class="col-lg-8 col-lg-offset-2" id="lstCompanies">
            </div>
        </div>
    </div>
    
    <script src="/LiberUI/Scripts/jquery.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    <script src="/SiteUI/res_sobiz.js"></script>

    <div id="tpls">
        <div class="companyView row">
            <h5 class="cv-name">企业名称</h5>
            <div class="col-lg-8">
                <span class="cv-industry">行业</span>
                <a class="LinkTo cv-website" target="_blank" href="#">官方网站</a>
                <br />
                <span class="cv-creater">创建人</span>
            </div>
            <div class="col-lg-2 cv-certify">
                企业认证
            </div>
            <div class="col-lg-2" style="text-align:center">
                <a class="btnApply">申请加入</a>
            </div>
        </div>
        <div class="col-lg-6 col-lg-offset-3" id="pnlCreateCompany">
            <span>找不到您所工作的企业？请点这里<a class="LinkTo" id="lnkCreateCompany" target="_self" href="/Company/NewCompany">创建企业</a></span>
        </div>
        <div id="joinApplyEnd">

        </div>
    </div>
    <div class="view" id="pageFoot">

    </div>
    <script>
        var SetCompany = {
            key: "",
            joinCompanyId:null,
            companies: [],  //所有查询结果
            tpls:document.createDocumentFragment(),
            tplCompanyView: null,
            pnlCreateCompany: null,
            Filtering:false,
            findCompany: function (ev) {
                var k = $("#txbCompany").vl().trim();
                if (!SetCompany.key||k.length>0 &&(k.indexOf(SetCompany.key)!=0||SetCompany.key.length==0)) {
                    //仅当新的输入值不是以原先的key为起始，才开始新的查询
                    SetCompany.companies.forEach(function (i) { i.View.remove(); i.View = null; });
                    SetCompany.companies = [];
                    SetCompany.key = k;
                    $.getJSON("/Company/FindCompany", { key: k }, SetCompany.findCompanyEnd);
                }
                else {
                    SetCompany.key =k;
                    SetCompany.filterCompany();
                }
                if (ev) {
                    setTimeout(SetCompany.findCompany, 1000);
                }
            },
            findCompanyEnd: function (rtn) {
                if (rtn.IsPositive) {
                    SetCompany.companies.forEach(function (i) { i.View.remove(); i.View = null; });
                    SetCompany.companies = [];
                    rtn.Data["companies"].forEach(SetCompany.makeCompanyView);
                }
                else {
                    //TODO:查询出现错误的处理
                }
                SetCompany.filterCompany();
            },
            filterCompany: function (refilter) {
                //TODO:针对查询结果执行过滤
                for (var n = 0; n < SetCompany.companies.length; n++) {
                    var i = SetCompany.companies[n];
                    if (i.companyname.indexOf(SetCompany.key) > -1 || i.summy.indexOf(SetCompany.key) > -1) {
                        i.View.appendTo("#lstCompanies").fadeIn();
                    }
                    else {
                        i.View.appendTo(SetCompany.tpls);
                    }
                }
                if (SetCompany.key.length > 0) {
                    SetCompany.pnlCreateCompany.insertAfter("#lstCompanies").fadeIn();
                }
                else {
                    SetCompany.pnlCreateCompany.appendTo(SetCompany.tpls);
                }
            },
            makeCompanyView: function (i) {
                i.View = SetCompany.tplCompanyView.clone();
                i.View.find(".cv-name").vl(i.companyname);
                i.View.find(".cv-connection").vl(i.officephone + "  " + i.address);
                i.View.find(".cv-industry").vl("所属行业:" + i.industry);
                if (i.website.indexOf("未设置")>0||i.website=="") {
                    i.View.find(".cv-website").attr("href", "#").vl("");
                }
                else {
                    i.View.find(".cv-website").attr("href", i.website).vl("官方网站：" + i.website);
                    
                }
                i.View.find(".cv-creater").vl("创建人："+i.creater);
                i.View.attr("objid", i.idstr);
                if (i.certifystatus == 'Completed') {
                    i.View.find(".cv-certify").vl($("<a class='Company certificated' >已认证</a>"));
                }
                else {
                    i.View.find(".cv-certify").vl($("<a class='Company non-certificated' >未认证</a>"));
                }
                SetCompany.companies.push(i);
            },
            joinCompany: function (ev) {
                var c = $(ev.currentTarget);
                var cv = c.parents(".companyView").eq(0);
                SetCompany.joinCompanyId = cv.attr("objid");
                if (SetCompany.joinCompanyId) {            
                    $.getJSON("/Company/ApplyJoin", { company: SetCompany.joinCompanyId }, SetCompany.joinCompanyEnd);
                }       
            },
            joinCompanyEnd: function (rtn) {
                //处理申请发出结果
                if (rtn.IsPositive) {
                    success("成功", "您的申请已发送给企业管理人员，稍后您可以在个人信息页面查看审核结果。<br/>现在将进入平台")
                           .on("disposed", function (ev) {window.location="/MyBiz/Index" });
                }
                else {
                    error("失败", "抱歉，您的申请未能发送，错误如下" + ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
                }
            }
        }
        $(function () {          
            var sign = window.location.search;
            sign = sign.substr(1, sign.length);
            if (sign == "Company") {
                $("#vr-success").hide();
                $("#vr-steps3").hide();
                $("#vr-company").css("margin-top", "8rem");
               
            }
            KeybordHelper.on($("#txbCompany"), "*", SetCompany.findCompany);
            $("#lstCompanies").delegate(".btnApply", "click", null, SetCompany.joinCompany);
            SetCompany.tplCompanyView = $(".companyView").eq(0).hide();
            SetCompany.pnlCreateCompany = $("#pnlCreateCompany").hide();
            $("#btnFind").on("click", function () {
                SetCompany.key = "";
                SetCompany.findCompany();
            });

            $("#pageFoot").load("/common/pageFoot.html");

            $("#txbCompany").focus();
        })
    </script>

    <div id="tplPrompt" style="display:none">
        <div class="prompt_success">
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
        <div class="prompt_info">
           
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
        <div class="prompt_err">
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
    </div>

    <script>
    window.success = function (title,msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_success").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();

    };
    window.info = function (title,msg, delay,fnCallback) {
        var cnt = $("#tplPrompt>.prompt_info").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };
    window.error = function (title, msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_err").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };

    window.log = function (msg) {
        if (console) {
            console.log(msg);
        }
    };

    </script>
</body>
</html>



